#include "SpawnPlugin.h"
#include "Log.h"
#include "Expand/PluginsManager.h"
#include "Game/IInventory.hpp"
#include "Managers/GameManager.h"
#include "Components/ComponentInventory.h"
#include "Components/ComponentPlayer.h"
#include "Components/ComponentBody.h"

#include "Network/Client.h"
#include "Player/PlayerData.h"

#include "Subsystems/SubsystemPlayers.h"

#include "ServerConfigure.h"
#include "GameSingleton.h"

#include "LiteNetLib/NetConstants.h"

namespace PocketSurvival
{
    const std::string &SpawnPlugin::getPluginName()
    {
        static const std::string pluginName = "回初始出生点插件";
        return pluginName;
    }

    const std::string &SpawnPlugin::getIntroduce()
    {
        static const std::string introduce = "\n/spawn - 回到初始出生点";
        return introduce;
    }

    uint32_t SpawnPlugin::getUseAuthLevel()
    {
        return 0;
    }

    AuthDisplayType SpawnPlugin::getDisplayType()
    {
        return AuthDisplayType::Authority;
    }

    void SpawnPlugin::processCmd(ChatObj &chatObj, std::vector<std::string> &cmdDataVec)
    {
        if(chatObj.m_isTerminal == true)
        {
            chatObj.sendMessage("Spawn", "控制台不能使用");
            return;
        }

        chatObj.m_client->playerData->componentPlayer->setNetPosition(GameSingleton::serverConfigure->startSpawnPoint);
    }

    void SpawnPlugin::getCmds(std::vector<std::string> &cmdVec)
    {
        cmdVec.push_back("/spawn");
    }

    void SpawnPlugin::load()
    {
        // int *ptr = nullptr;
        // *ptr = 45;
    }

} // namespace PocketSurvival


using namespace PocketSurvival;

extern "C" void initialize()
{
    GameSingleton::singletonPtr->getSingleton<PluginsManager>()->registerPlugin<SpawnPlugin>();
    Log::Info("成功加载 SpawnPlugin 插件");
}